n = input()

if len(n)!=4:
    print(0)
    exit()


n1, n2, n3, n4 = n[0], n[1], n[2], n[3]
a = [n1, n2, n3, n4, n1+n2, n2+n3, n3+n4, n1+n2+n3, n2+n3+n4]
b = []


for i in a:
    i = int(i)
    easy = True
    for j in range(2, i):
        if i % j == 0:
            prost = False
            break
    if easy:
        b.append(i)


if len(b) == 0:
    print(0)
    exit()


print(max(b))